package core;

import java.io.File;
import java.util.List;

import stemmer.NullStemmer;
import stemmer.Stemmer;
import utility.file.TextFile;
import utility.lines.Lines;
import wordnet.IWordnetOperator;
import wordnet.NaiveWordnetOperator;

public class Main {
	
	public static final double TRAINING_WINNOW_COEFFICIENT = 0.01;
	public static final double TEST_WINNOW_COEFFICIENT = 0.01;
	public static final int N_WORDS = 2;

	public static void main(String[] args){
		List<String> trainQuestions = Lines.from(new File("..\\materials\\train.txt")).asList();
		File resultTrainingFile = new File("..\\materials\\training_results.csv");
		TextFile resultTrainingTextFile = TextFile.inRewrite(resultTrainingFile);
		resultTrainingTextFile.putLine("Numero Training\\Matrice;;Class;TP;FP;FN;TN;;Error Rate;Accuracy;Precision;Recall;Break-Even;F1-Measure");
		resultTrainingTextFile.putLine(";;;;;;");
		
		Stemmer stemmer = new NullStemmer();
		IWordnetOperator wordnetOperator = new NaiveWordnetOperator();
		Trainer trainer = new Trainer();
		int trainingCount = 0;
		for (String each : trainQuestions) {
			trainer.putQuestionUsing(each, wordnetOperator, stemmer);
			trainer.writeResultsOn(resultTrainingTextFile);
			resultTrainingTextFile.putLineInCache(";;;;;;");
			trainingCount++;
			System.out.println(trainingCount+" \\ "+trainQuestions.size());
		}
		resultTrainingTextFile.forceWriting();
		
		List<String> testQuestions = Lines.from(new File("..\\materials\\test.txt")).asList();
		Tester tester = trainer.tester();
//		tester.makeTfIdf();
		File resultTestFile = new File("..\\materials\\test_results.csv");
		TextFile resultTestTextFile = TextFile.inRewrite(resultTestFile);
		resultTestTextFile.putLine("Numero di Test\\Matrice;;Class;TP;FP;FN;TN;;Error Rate;Accuracy;Precision;Recall;Break-Even;F1-Measure");
		resultTestTextFile.putLine(";;;;;;");
		int testCount = 0;
		for (String each : testQuestions) {
			tester.test(each);
			testCount++;
			System.out.println(testCount+" \\ "+testQuestions.size());
		}
		tester.writeResultsOn(resultTestTextFile);
		resultTestTextFile.forceWriting();
		
		System.out.println(tester.result());
	}
}
